<template>
	<view class="quote-list">
		<view class='list' v-if="quoteEntities">
			<view class='item' v-for="(quote, index) in quoteEntities" :key="index" @click='querySingle(project)'>
				<view class='top'>
					<view class='number-box line'>
						<view class='project-number'>{{quote.projectName}}</view>
						<view class='status'>
							<uni-tag :text="quote.status==0?'未审批':(quote.status==1?'审批中':'已审批')"
								:type="quote.status==0 ? 'error' : (quote.status==1?'success':'primary')" />
						</view>
					</view>
					<view class='name-box line'>{{quote.companyName == null ? '--' : quote.companyName}}</view>
					<view class='name-box line'>{{quote.totalPrice == null ? '--' : '￥'+quote.totalPrice}}</view>
					<view class="line">
						<uni-tag :text="quote.type==0?'采购报价':'销售报价'" :type="quote.type==0 ? 'success':'primary'" />
					</view>
					<view class='partner-box line'>{{quote.payStatus}}</view>
					<view class='user-box line'>
						<view class='user'>{{quote.userName}}</view>
					</view>
				</view>
				<view class='createTime'>
					<text class="iconfont icon-rili"></text>创建时间：
					<uni-dateformat :date="quote.createTime" format='yyyy-MM-dd hh:mm:ss'></uni-dateformat>
				</view>
			</view>
		</view>
		<uni-load-more iconType="circle" v-if="quoteEntities.length" :status="loadingStatus"></uni-load-more>
		<o-empty v-else bg="#f3f3f3"></o-empty>
	</view>
</template>

<script>
	import {
		api,
		post
	} from '../../util/api'
	export default {
		data() {
			return {
				quoteEntities: [],
				page: 1,
				limit: 10,
				count: 0,
				loadingStatus: 'more',
				applyUserId: null,
				isUsed: 1
			}
		},
		created() {
			this.queryList()
		},
		beforeMount() {
			uni.$on('onReachBottomQuote', () => {
				this.onReach()
			})
			uni.$on('addQuote', () => {
				uni.navigateTo({
					url: '/pages/quote/AddQuote'
				})
			})
			uni.$on('reloadQuoteList', () => {
				uni.$emit('financeList', 1)
				uni.switchTab({
					url: '/pages/finance/FinanceNav'
				})
				this.quoteEntities = []
				this.queryList()
			})
		},
		destroyed() {
			uni.$off('onReachBottomQuote')
			uni.$off('addQuote')
			uni.$off('reloadQuoteList')
		},
		methods: {
			async queryList() {
				let quote = {
					page: this.page,
					limit: this.limit,
					isUsed: 1
				}
				let res = await post(api.QuoteEntities, quote)
				this.count = res.count
				this.loadingStatus = "more"
				this.quoteEntities = [...this.quoteEntities, ...res.data]
			},
			//上拉刷新处理
			async onReach() {
				if (this.quoteEntities.length >= this.count) {
					return (this.loadingStatus = "no-more")
				}
				this.page++
				this.loadingStatus = "loading"
				await new Promise((resolve) => setTimeout(resolve, 300))
				await this.queryList()
			},
		}
	}
</script>

<style lang="less">
	@import '../../static/css/QuoteList.css';
</style>
